package com.arsn.myf.common.listener;

import com.arsn.myf.common.event.ApiLogEvent;
import com.arsn.myf.system.entity.ApiLog;
import com.arsn.myf.system.service.ApiLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * apiLog 监听器（监听日志事件）
 * @author zhongrj
 * @since 2022-08-10
 */
@Component
public class ApiLogListener {

    @Autowired
    private ApiLogService apiLogService;

    /**
     * 今天api log 事件 日志保存
     * @param event 事件
     */
    @EventListener(ApiLogEvent.class)
    @Order
    public void saveApiLog(ApiLogEvent event){
        Map<String,Object> source = (Map<String,Object>)event.getSource();
        ApiLog apiLog = (ApiLog) source.get("log");
        //保存日志
        apiLogService.save(apiLog);
    }

}
